package com.lzc.tlmail.tlmailproduct.web;

import com.lzc.tlmail.tlmailproduct.entity.CategoryEntity;
import com.lzc.tlmail.tlmailproduct.service.CategoryService;
import com.lzc.tlmail.tlmailproduct.vo.Level2Vo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author lzc
 * @create 2020-09-23 20:49
 */
@Slf4j
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 获取一级分类
     * @param model
     * @return
     */
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
      List<CategoryEntity> categoryEntities=categoryService.queryLevel1Category();
        model.addAttribute("categorys",categoryEntities);
        return "index";
    }

    //index/json/catalog.json

    /**
     * 获取一级分类下所有分类
     * @return
     */
    @ResponseBody
    @GetMapping("index/json/catalog.json")
    public Map<String,List<Level2Vo>> getLevel2Category(){
        Map<String,List<Level2Vo>> listMap=categoryService.getLevel2Category();
        return listMap;
    }
}
